import org.junit.Test;

import java.io.*;
import java.time.LocalDateTime;
import java.util.stream.Stream;

/**
 * @program: java_zzx
 * @description:
 * @author: zzx
 * @create: 2022-10-31 14:24
 **/
public class Demo {
    @Test
    public static void write(String[] args) throws IOException {
        File file = new File("new.txt");
        OutputStream out = new FileOutputStream(file);
        String str = "用字节流想文件输出内容hello\r\n";
        byte[] data = str.getBytes();
        out.write(data);
        String now = "当前时间：" + LocalDateTime.now();
        out.write(now.getBytes());
        out.close();
    }
    @Test
    public void read() throws IOException {
        File file = new File("new.txt");
        FileInputStream in = new FileInputStream(file);
        byte[] arr = new byte[10];
        in.read();
    }



    @Test
    public void copy(){
        //创建文件字节输入流
        //创建文件字节输出流
        try (FileInputStream inputStream = new FileInputStream("D:\\Java学习笔记\\文本\\c.txt");
             FileOutputStream outputStream = new FileOutputStream("D:\\Java学习笔记\\文本\\cc.txt");) {
            //准备byte数组
            byte[] bytes = new byte[1024];//一次最多读取1KB。
            //一边读
            int readCount = 0;
            while((readCount = inputStream.read(bytes)) != -1){
                outputStream.write(bytes,0,readCount);
            }
            //刷新
            outputStream.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
